<?php
declare (strict_types=1);

namespace app\course\logic\cart\admin;

use app\course\model\cart\admin\Cart as CartModel;
use app\user\logic\user\admin\Account;

/**
 * Class Cart
 *
 * @package app\course\logic\cart\admin
 */
class Cart extends CartModel
{
    /**
     * 获取列表
     * Author: Martinsun <syh@sunyonghong.com>
     * Date: 2021/10/27
     *
     * @param array  $map
     * @param string $phone
     * @return \think\Paginator
     * @throws \think\db\exception\DbException
     */
    public function getList(array $map = [], string $phone = '')
    {
        $builder = $this->with(['user']);
        if ($phone) {
            // $user_id = Account::withoutGlobalScope(['mhm'])->where('phone', $phone)->removeOption('soft_delete')->value('id');
            $user_id = Account::where('phone', $phone)->removeOption('soft_delete')->value('id');

            $builder = $builder->where('user_id', $user_id);
        }

        return $builder->where($map)->order('create_time', 'DESC')->paginate($this->getListRows());
    }
}